package com.ellecity06.common.base

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.viewbinding.ViewBinding
import com.chad.library.adapter.base.BaseQuickAdapter

/**
 * @author ellecity06
 * @time 2023/4/17 12:02
 * @des
 */
abstract class BaseAdapter<T, VB : ViewBinding> : BaseQuickAdapter<T, BaseViewHolder<VB>>() {
    abstract fun inflateBinding(layoutInflater: LayoutInflater, parent: ViewGroup, viewType: Int): VB
    abstract fun convert(binding: VB, position: Int, item: T)
    override fun onBindViewHolder(holder: BaseViewHolder<VB>, position: Int, item: T?) {
        if (item == null) return
        convert(holder.binding, position, item)
    }

    override fun onBindViewHolder(holder: BaseViewHolder<VB>, position: Int, item: T?, payloads: List<Any>) {
        super.onBindViewHolder(holder, position, item, payloads)
    }

    override fun onCreateViewHolder(context: Context, parent: ViewGroup, viewType: Int): BaseViewHolder<VB> {
        val binding = inflateBinding(LayoutInflater.from(context), parent, viewType)
        return BaseViewHolder(binding)

    }
}